POV-Ray : Newsgroups : povray.newusers : Macro Woes : Re: Macro Woes Server Time
5 Sep 2024 20:19:39 EDT (-0400)
  Re: Macro Woes  
From: Jon A  Cruz
Date: 30 Sep 1999 03:57:12
Message: <37F317EA.3BBE25D1@geocities.com>
Nieminen Juha wrote:

> Jon A. Cruz <jon### [at] geocitiescom> wrote:
> : Or, if you really want to use 'object', then just
>
> : #delcare anInstance = SphereMacro(15, 1, 1.5, 10)
> : object {
> :   anInstance
> : }
>
>   What's wrong with
>
> object { SphereMacro(15, 1, 1.5, 10) }
>
> ?
>
>   It's shorter and as clear as using a previous #declare.
>   It's easy to add transformations:
>
> object
> { SphereMacro(15, 1, 1.5, 10)
>   scale 10 translate -x*5
> }
>

Well, the main thing wrong with "object { SphereMacro(15, 1, 1.5, 10) }" is
that at least with the way he has his macro defined, it will cause errors in
POV-Ray. The object needs the #declared to work.

But, if his macro were changed to create a single POV-Ray object, then it
could be used in such a case. At the moment it creates a set of objects, and
not a single object.

Well, I guess I'd better re-work things so that he can do the simple
object{} thing.

Here it is. Notice the extra "union {" added after the "just in case"
comment. And the closing "}" just before the last end. That's the main magic
to get it to work.

#macro SphereMacro(Amount, StartSize, SizeDivide, RotationSpeed)
  #local Counter = 0;
  #local Pos = 0;
  #local SizeNow = StartSize;
  #local Rotation = 0 - RotationSpeed;

// Note: Some statements are commented out, as you can see.
// This is some code from the old macro that I didn't want to remove
// just in case. . . :(
  union {
    #while (Counter < Amount)
//    #if (Counter != 0)
      union {
 #local SizeNow = SizeNow / SizeDivide;
 #local Pos = Pos+(SizeDivide*SizeNow);
 #local Rotation = Rotation + RotationSpeed;
 sphere { <0-Pos, 0+Pos, 0-Pos>, SizeNow texture{SphereTexture} }
 sphere { <0+Pos, 0+Pos, 0-Pos>, SizeNow texture{SphereTexture} }
 sphere { <0-Pos, 0-Pos, 0-Pos>, SizeNow texture{SphereTexture} }
 sphere { <0+Pos, 0-Pos, 0-Pos>, SizeNow texture{SphereTexture} }
 rotate <0, 0, Rotation>
      }
//    #else

// ---
// The original purpose of the following statement was to save you
// 3 objects.
// --
      sphere { <0,0,0>, StartSize texture{SphereTexture} }
//    #end
      #debug concat(str(Counter, 0, 0) + "th Loop")
      #declare Counter = Counter + 1;
    #end
  }
#end


--
"My new computer's got the clocks, it rocks
But it was obsolete before I opened the box" - W.A.Y.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.